package com.bawei.module_mine.http.repository

import com.bawei.lib_net.RetrofitFactory
import com.bawei.module_mine.http.api.LoginApiService
import com.bawei.module_mine.model.AddAccountModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn

class LoginRepository {

    val api: LoginApiService

    init {
        api = RetrofitFactory.getRetrofitFactory().create(LoginApiService::class.java)
    }

    fun getLogin(username: String, password: String) = flow {
        emit(api.getLogin(username, password))
    }.flowOn(Dispatchers.IO)

    fun getAddAccount(body: AddAccountModel) = flow {
        emit(api.getAddAccount(body))
    }.flowOn(Dispatchers.IO)

    fun getFindAccountById(id: Int) = flow {
        emit(api.getFindAccountById(id))
    }.flowOn(Dispatchers.IO)

    fun getLike(sourceflag: String, userId: Int) = flow {
        emit(api.getLike(sourceflag, userId))
    }.flowOn(Dispatchers.IO)

    fun setImg(id: Int, img: String) = flow {
        emit(api.setImg(id, img))
    }.flowOn(Dispatchers.IO)

    fun quickLogin(exId: String, loginToken: String) = flow {
        emit(api.quickLogin(exId, loginToken))
    }.flowOn(Dispatchers.IO)

    fun getMine() = flow {
        emit(api.getMine())
    }.flowOn(Dispatchers.IO)
}